<#include "/common/head.html"/>
    
    <table id="dg"></table>
    <div id="tb" style="padding:2px 5px;">
        <div class="wrap_search">
		            	<span class="search_item">
			            	<span class="item_text">Job类型: </span>
			            	<span class="item_obj">
			            		<input class="easyui-combobox" name="job_type" id="job_type" value="" style="width:100px" data-options="
			            				valueField: 'id',
        								textField: 'text',
			            				data: [
			            					{id:'', text:''}<#list job_type.keySet() as key>,{id:'${key}', text:'${job_type.get(key)}'}</#list>
			            				]
			            			" />
			            	</span>    
			           	</span>		        		
			            	<span class="search_item">
				            	<span class="item_text">job名称: </span>
				            	<span class="item_obj">
				            		<input class="easyui-textbox" type="text" name="job_name" id="job_name" value=""/>
				            	</span>    
				            </span>
		        		
			            	<span class="search_item">
				            	<span class="item_text">job组: </span>
				            	<span class="item_obj">
				            		<input class="easyui-textbox" type="text" name="job_group" id="job_group" value=""/>
				            	</span>    
				            </span>				           
			            	<span class="search_item">  
			            	 <span class="item_text">Job运行状态: </span>
			            	<span class="item_obj">
			            		<input class="easyui-combobox" name="run_status" id="run_status" value="" style="width:100px" data-options="
			            				valueField: 'id',
        								textField: 'text',
			            				data: [
			            					{id:'', text:''}<#list run_status.keySet() as key>,{id:'${key}', text:'${run_status.get(key)}'}</#list>
			            				]
			            			" />
			            	</span> 
			            	</span> 
			        		<span class="search_item search_between">
				                <span class="item_text">单次任务运营时间: </span>
				                <span class="item_obj">
				                    <input class="easyui-datebox" name="_start_start_time" id="_start_start_time" value=""/> ～ <input class="easyui-datebox" name="_end_start_time" id="_end_start_time" value=""/>
				                </span>
				            </span>
				            
				           
        </div>
        <div style="text-align: left; margin:6px;">
            <a href="javascript:void(0)" class="easyui-linkbutton detailBtn" iconCls="glyphicon-export" plain="true" onclick="exportCsv()">导出</a> 
            <a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" plain="true" onclick="add()">增加</a>
           	<a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" plain="true" onclick="update()">编辑</a>
           	<a href="javascript:void(0)" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove" plain="true" onclick="del()">删除</a>
           	<a href="javascript:void(0)" >|</a>  
            <a href="javascript:void(0)" class="easyui-linkbutton startJobBtn" iconCls="glyphicon-play" plain="true" onclick="startJob()">启动任务</a>
            <a href="javascript:void(0)" class="easyui-linkbutton stopJobBtn" iconCls="glyphicon-stop" plain="true" onclick="stopJob()">停止任务</a>
            <a href="javascript:void(0)" class="easyui-linkbutton pauseJobBtn" iconCls="glyphicon-pause" plain="true" onclick="pauseJob()">暂停任务</a>
            <a href="javascript:void(0)" class="easyui-linkbutton resumeJobBtn" iconCls="glyphicon-refresh" plain="true" onclick="resumeJob()">恢复任务</a>
            <div id="searchBtnWrap" style="float:right; padding-right:40px;">
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="glyphicon-search" onclick="zcurdSearch(this)">搜索</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="glyphicon-repeat" onclick="flushPage()">重置</a>
            </div>
        </div>
    </div>
    

<script type="text/javascript">
var datagrid = $("#dg");

var dgOptions = {
        rownumbers:true,
    	//fit:true,
    	border:false,
        rownumbers:true,
    	url:'listData',
    	method:'post',
    	toolbar:'#tb',
    	height:400,
    	pageSize: 20,
    	pagination:true,
    	multiSort:true,
        queryParams: getInitParam(),
        
        columns: [[
		         {field:'id', checkbox:true}
	           	 ,{field:'job_name', title: 'Job名称', width:100, sortable: true}
	           	 ,{field:'job_class', title: 'Job实现类', width:150, sortable: true}
	           	 ,{field:'job_group', title: 'Job组', width:80, sortable: true}
	           	 ,{field:'job_cron', title: 'Job时间规则（周期任务）', width:180, sortable: true}
	             ,{field:'job_type', title: 'Job类型', width:80, sortable: true}
	             ,{field:'job_desc', title: 'Job描述', width:150, sortable: true}
	           	 ,{field:'start_time', title: '执行时间', width:120, sortable: true}
	           	 ,{field:'run_status', title: '运行状态（单次任务）', width:150, sortable: true}
	           ]]
	};
$(function() {
	handleAuthDataRule();
	datagrid.datagrid(dgOptions);
});

function zcurdSearch() {
	var param = zcurdGetParam();
	datagrid.datagrid("load", {
		queryParams: param
	})
}

function zcurdGetParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param[$(item).attr("name")] = $(item).val();	
		}
	});
	return param;
}

function getInitParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param["queryParams[" + $(item).attr("name") + "]"] = $(item).val();	
		}
	});
	return param;
}

function exportCsv() {
	var option = datagrid.datagrid("options");
	var param = option.queryParams;
	param.sortName = option.sortName;
	param.sortOrder = option.sortOrder;
	window.location.href = "exportCsv?" + $.param(param);
}

function add() {
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("增加成功！");
		datagrid.datagrid("load");
	}
	top.openWindow("作业管理-增加", "${basePath}/job/addPage?" ,{width: 600, heigth: 400});
}

function update() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择一条数据！");
		return;
	}
	var id = rowsSel[0].id;
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("更新成功！");
		datagrid.datagrid("load");
	}
	top.openWindow("作业管理-编辑", "${basePath}/job/updatePage?id=" + id, {size: '600x400'});
}

function del() {
	var ids = [];
	$.each(datagrid.datagrid("getSelections"), function(i, item) {
		ids.push(item.id);
	});
	if(ids.length < 1) {
		showWarnMsg("请选择需要删除的数据！");
		return;
	}
	confirmMsg("确认删除？", function() {
		$.post("delete", {id: ids}, function(data) {
			showMsg("删除成功！");
			datagrid.datagrid("load");
		});
	});
}
//启动任务
function startJob() {
	var ids = [];
	$.each(datagrid.datagrid("getSelections"), function(i, item) {
		ids.push(item.id);
	});
	if(ids.length < 1) {
		showWarnMsg("请选择需要操作的数据！");
		return;
	}
	confirmMsg("确认操作？", function() {
		$.post("startJob", {id: ids}, function(data) {
			showMsg("操作成功！");
			datagrid.datagrid("load");
		});
	});
}
//停止任务
function stopJob() {
	var ids = [];
	$.each(datagrid.datagrid("getSelections"), function(i, item) {
		ids.push(item.id);
	});
	if(ids.length < 1) {
		showWarnMsg("请选择需要操作的数据！");
		return;
	}
	confirmMsg("确认操作？", function() {
		$.post("stopJob", {id: ids}, function(data) {
			showMsg("操作成功！");
			datagrid.datagrid("load");
		});
	});
}
//暂停任务
function pauseJob() {
	var ids = [];
	$.each(datagrid.datagrid("getSelections"), function(i, item) {
		ids.push(item.id);
	});
	if(ids.length < 1) {
		showWarnMsg("请选择需要操作的数据！");
		return;
	}
	confirmMsg("确认操作？", function() {
		$.post("pauseJob", {id: ids}, function(data) {
			showMsg("操作成功！");
			datagrid.datagrid("load");
		});
	});
}
//恢复任务
function resumeJob() {
		var ids = [];
		$.each(datagrid.datagrid("getSelections"), function(i, item) {
			ids.push(item.id);
		});
		if(ids.length < 1) {
			showWarnMsg("请选择需要操作的数据！");
			return;
		}
		confirmMsg("确认操作？", function() {
			$.post("resumeJob", {id: ids}, function(data) {
				showMsg("操作成功！");
				datagrid.datagrid("load");
			});
		});
}

</script>

<#include "/common/dialogWindow.html"/>
<#include "/common/foot.html"/>